package point

import (
	"os/exec"
	"regexp"
	"strconv"
)

type CpuDiskSizePoint struct{}

func NewCpuDiskSizePoint() *CpuDiskSizePoint { return &CpuDiskSizePoint{} }

func (m *CpuDiskSizePoint) Get() any {

    getDiskSize := func() uint32 {
        out, _ := exec.Command("lsblk").Output()    
        re := regexp.MustCompile(`mmcblk1\s+\d+:\d+\s+\d+\s+([\d.]+)([GM])`)
        matches := re.FindStringSubmatch(string(out))
    
        if len(matches) == 3 {
            sizeStr := matches[1]
            unit := matches[2]
    
            // 转换为 MB
            var sizeInMB float64
            if unit == "G" {
                sizeInMB, _ = strconv.ParseFloat(sizeStr, 64)
                sizeInMB *= 1024 
            } else {
                sizeInMB, _ = strconv.ParseFloat(sizeStr, 64)
            }
            return uint32(sizeInMB)
        } 

        return 0
    }

    return getDiskSize()
} 

func (m *CpuDiskSizePoint) Set(...any) bool { return false }

func (m *CpuDiskSizePoint) SetRoute(string) PointInterface { return m }
